package com.ruoyi.project.warehouseSystem.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.warehouseSystem.domain.ComptClassify;
import com.ruoyi.project.warehouseSystem.service.IComptClassifyService;
import com.ruoyi.project.warehouseSystem.service.IDocumentClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 档案分类Controller
 *
 * @author wangshuo
 * @date 2021-01-22
 */
@RestController
@RequestMapping("/warehouseSystem/documentClassify")
public class DocumentClassifyController extends BaseController
{
    @Autowired
    private IComptClassifyService comptClassifyService;
    @Autowired
    private IDocumentClassifyService documentClassifyService;

    /**
     * 查询档案分类列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:documentClassify:list')")
    @GetMapping("/list")
    public TableDataInfo list(ComptClassify comptClassify)
    {
        startPage();
        List<ComptClassify> list = documentClassifyService.selectComptClassifyList(comptClassify);
        return getDataTable(list);
    }

    /**
     * 导出档案分类列表
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:documentClassify:export')")
    @Log(title = "档案分类", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ComptClassify comptClassify)
    {
        List<ComptClassify> list = documentClassifyService.selectComptClassifyList(comptClassify);
        ExcelUtil<ComptClassify> util = new ExcelUtil<ComptClassify>(ComptClassify.class);
        return util.exportExcel(list, "comptClassify");
    }

    /**
     * 获取档案分类详细信息
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:documentClassify:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(documentClassifyService.selectComptClassifyById(id));
    }

    /**
     * 新增档案分类
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:documentClassify:add')")
    @Log(title = "档案分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComptClassify comptClassify)
    {
        return toAjax(documentClassifyService.insertComptClassify(comptClassify));
    }

    /**
     * 修改档案分类
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:documentClassify:edit')")
    @Log(title = "档案分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComptClassify comptClassify)
    {
        return toAjax(documentClassifyService.updateComptClassify(comptClassify));
    }

    /**
     * 删除档案分类
     */
    @PreAuthorize("@ss.hasPermi('warehouseSystem:documentClassify:remove')")
    @Log(title = "档案分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(documentClassifyService.deleteComptClassifyByIds(ids));
    }

    /**
     * 获取档案分类下拉树列表
     */
    @GetMapping("/treeselect")
    public AjaxResult treeselect(ComptClassify comptClassify)
    {
        List<ComptClassify> comptClassifies = documentClassifyService.selectComptClassifyList(comptClassify);
        return AjaxResult.success(documentClassifyService.buildComptClassifyTreeSelect(comptClassifies));
    }
}
